package com.sr.examination.exam.common.adapter;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.ListView;
import android.widget.TextView;

import com.sr.examination.R;
import com.sr.examination.exam.common.PayModel;
import com.tl.commonlibrary.ui.adapter.IAdapter;
import com.tl.commonlibrary.ui.adapter.ViewHolder;
import com.tl.commonlibrary.ui.beans.ExamBean;

import java.util.List;

/**
 * Created by JongSung on 18/3/1.
 */

public class ExamAdapter extends IAdapter<ExamBean> {

    private PayModel payModel;

    public ExamAdapter(Context context, List<ExamBean> datas) {
        super(context, datas, R.layout.item_exam);
    }

    public void setPayModel(PayModel payModel) {
        this.payModel = payModel;
    }

    @Override
    protected void getView(ViewHolder viewHolder, ExamBean entity, int position, View convertView, boolean isConvert, int itemViewType, ViewGroup parent) {
        TextView titleTView = viewHolder.getView(R.id.titleTView);
        titleTView.setText(entity.getTitle());
        ListView listView = viewHolder.getView(R.id.examSubLView);
        ExamSubAdapter examSubAdapter = (ExamSubAdapter) listView.getAdapter();
        if (examSubAdapter != null) {
            examSubAdapter.setDatas(entity.getPapers());
        } else {
            examSubAdapter = new ExamSubAdapter(context, entity.getPapers());
            examSubAdapter.setPayModel(payModel);
            listView.setAdapter(examSubAdapter);
            listView.setDivider(new ColorDrawable(ContextCompat.getColor(context, R.color.transparent)));
            listView.setDividerHeight((int) context.getResources().getDimension(R.dimen.base_spacing_20px));
        }
    }

    @Override
    public void onClick(View v) {

    }
}
